<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 800px;
            height: 400px;
            background: pink;
            position: relative;
            margin: auto;
        }

        .box div {
            position: absolute;
            width: 200px;
            height: 100px;
            background: blue;
            /* 定位后元素水平居中 */
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }
    </style>
</head>

<body>
    <!-- 水平垂直居中 -->
    <div class="box">
        <div></div>
    </div>
</body>

</html>